// 长连接测试1：创建一个客户端持续给服务器发送数据，直到超过超时间看看是否正常
#include "../http/http.hpp"

int main()
{
    Socket socket;
    socket.CreateClient(8085,"127.0.0.1");
    std::string req="GET /hello HTTP/1.1\r\nConnection: keep-alive\r\nContent-Length: 0\r\n\r\n";
    req+="GET /hello HTTP/1.1\r\nConnection: keep-alive\r\nContent-Length: 0\r\n\r\n";
    req+="GET /hello HTTP/1.1\r\nConnection: keep-alive\r\nContent-Length: 0\r\n\r\n";
    while(1){
        assert(socket.Send(req.c_str(),req.size())!=-1);
        char buf[1024]={0};
        assert(socket.Recv(buf,1023));
        DBG_LOG("[%s]",buf);
        sleep(3);
    }
    socket.Close();
    return 0;
}








// int main()
// {
//     signal(SIGCHLD,SIG_IGN);
//     for(int i=0;i<10;i++){
//         pid_t pid=fork();
//         if(pid<0){
//             return -1;
//         }else if(pid==0){
//             Socket socket;
//             socket.CreateClient(8085,"127.0.0.1");
//             std::string req="GET /hello HTTP/1.1\r\nConnection: keep-alive\r\nContent-Length: 0\r\n\r\n";
//             while(1){
//                 assert(socket.Send(req.c_str(),req.size())!=-1);
//                 char buf[1024]={0};
//                 assert(socket.Recv(buf,1023));
//                 DBG_LOG("[%s]",buf);
//                 sleep(3);
//             }
//             socket.Close();
//             exit(0);
//         }
//     }
//     while(1) sleep(1);
//     return 0;
// }





// int main()
// {
//     Socket socket;
//     socket.CreateClient(8085,"127.0.0.1");
//     std::string req="GET /hello HTTP/1.1\r\nConnection: keep-alive\r\nContent-Length: 100\r\n\r\nbitjiuyeke";
//     while(1){
//         assert(socket.Send(req.c_str(),req.size())!=-1);
//         assert(socket.Send(req.c_str(),req.size())!=-1);
//         assert(socket.Send(req.c_str(),req.size())!=-1);
//         assert(socket.Send(req.c_str(),req.size())!=-1);
//         char buf[1024]={0};
//         assert(socket.Recv(buf,1023));
//         DBG_LOG("[%s]",buf);
//         sleep(3);
//     }
//     socket.Close();
//     return 0;
// }
